package geometry3D;

import context.*;

import geometry2D.MetricPoint2D;

import javax.vecmath.Point3f;
import javax.vecmath.Vector3f;

// ********************************************************************
// *** CLASS: Point3D
// ********************************************************************
public class Point3D implements Context.Constants
{ //private static final boolean DEBUG=true; // Overriding Context.Constants.DEBUG
  static final String TAG="geometry3D.Point3D";
  
  public double x;
  public double y;
  public double z;

  public Point3D(double x,double y,double z)
  { this.x=x; this.y=y; this.z=z; }
  
  public Vector3f toVector3f() { return(new Vector3f((float)x,(float)y,(float)z)); }
  public Point3f toPoint3f() { return(new Point3f((float)x,(float)y,(float)z)); }

  public Point3D addX(double dx) { return(new Point3D(x+dx,y,z)); }
  public Point3D addY(double dy) { return(new Point3D(x,y+dy,z)); }
  public Point3D addZ(double dz) { return(new Point3D(x,y,z+dz)); }
    
  // ***************************************************************************
  // *** METHOD: toPoint2D -- NOTE: See also: Block.toProjection2D
  // ***************************************************************************
  // 3D ==> 2D projections the XZ, XY or ZY-plane
  public MetricPoint2D toPoint2D(int direction)//,Point3D origo3D)
  { double x1=0,y1=0;
    switch(direction)
    { case ABOVE: x1=x;   y1=z;   break; // Horisontial projection seen from above onto the XZ-plane
      case BELOW: x1=x;   y1= -z; break; // Horisontial projection seen from below onto the XZ-plane
      case SOUTH: x1=x;   y1= -y; break; // Vertical projection seen from south onto the XY-plane
      case NORTH: x1= -x; y1= -y; break; // Vertical projection seen from north onto the XY-plane
      case EAST:  x1= -z; y1= -y; break; // Vertical projection seen from east onto the ZY-plane
      case WEST:  x1=z;   y1= -y; break; // Vertical projection seen from west onto the ZY-plane
    }       
    return(new MetricPoint2D(x1,y1));
  }

  public String toString()
  { return("Point3D[x="+x+",y="+y+",z="+z+']'); }
}
